from flask import Flask, jsonify, request, jsonify, session
# socket 版本匹配 vue
# https://github.com/miguelgrinberg/python-socketio/issues/578
# https://stackoverflow.com/questions/65636439/how-to-get-javascript-socket-io-version#
from flask_socketio import SocketIO, send, emit, join_room, leave_room
# 解决跨域问题的模块CORS
from flask_cors import CORS

import json


app = Flask(__name__)


# 服务器允许 http跨域, socket跨域
CORS(app, supports_credentials = True, cors_allowed_origins="*")





@app.route('/', methods=['get', 'post'])
def hello():
    data={'state':'Hello world!'}
    MSH = request.form.get('MSH')
    print("You get it!", MSH)
    # return "Hello world!"
    return jsonify(data)


resSets = {'state':'Hello world!'}
@app.route('/postdata', methods=['POST'])
def postdata():
    data = request.form.get("MSH")
    print("You get it!", data)
    return json.dumps(resSets, ensure_ascii=False)
    # return jsonify(data)



if __name__=='__main__':
    # 数据库建表
    # db.create_all()
    # 应用运行
    app.run(debug=True)
    # socketio.run(app)
    # socketio.run(app, host='0.0.0.0', port=5000, debug=True)
    # socketio.run(app,debug=True)
    
